let db = require('../db/index')

exports.get = (req,res) =>{//通过姓名查询数据
    var sql = "select * from goods where iname like '%' ?"
    db.query(sql,[req.query.iname],(err,data)=>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })
}

exports.del = (req,res) =>{//通过姓名删除数据
    var sql = 'delete from goods where iname = ?'
    db.query(sql,[req.query.iname],(err,data) =>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })

}

exports.add = (req,res)=>{
    var sql = 'insert into goods (iname,pname,method,datatype,address,id) values (?,?,?,?,?,?)'
    db.query(sql, [req.query.iname, req.query.pname, req.query.method, req.query.datatype, req.query.address, req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}

exports.update = (req,res)=>{
    var sql = 'update goods set iname = ?, pname = ?,method = ?,datatype = ?,address = ? where id = ?'
    db.query(sql, [req.query.iname,req.query.pname,req.query.method,req.query.datatype,req.query.address,req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}